package iosr11.example;
import iosr11.data.Student;
import iosr11.gbase.dao.DAOLocator;
import iosr11.gbase.dao.DAOLocatorImpl;
import iosr11.gbase.dao.StudentDAO;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// Student(String realUserName, String email, int indexNumber, String
		// studentId, List<String> groups){
		/*BufferedReader stdin = new BufferedReader(new InputStreamReader(
				System.in));
		DAOLocator factory = DAOLocatorImpl.getInstance();
		String name = new String();
		String email = new String();
		int indexNumber = 0;
		boolean nowy = true;
		while (true) {
			try {
				System.out.println("N/n - dodanie nowego studenta");
				System.out.println("W/w - wyszukanie studenta");
				System.out.println("Inny klawisz - wyjście");
				name = stdin.readLine();
				if (name.equals("N") || name.equals("n"))
					nowy = true;
				else if (name.equals("W") || name.equals("w"))
					nowy = false;
				else
					throw new Exception();
			} catch (Exception e) {
				System.err.println("Wyjscie");
				System.exit(0);
			}
			// dodawanie nowego studenta
			if (nowy) {
				try {
					System.out.print("Podaj nazwisko i imie: ");
					name = stdin.readLine();
					System.out.print("Podaj e-mail: ");
					email = stdin.readLine();
					System.out.print("Podaj numer indexu: ");
					String tmpInt = stdin.readLine();
					indexNumber = Integer.parseInt(tmpInt);
					System.out.println("Nazwisko i Imie: " + name);
					System.out.println("e-mail: " + email);
					System.out.println("Numer indexu: " + indexNumber);
					System.out.println("Czy dane sa poprawn?(T)");
					tmpInt = stdin.readLine();
					if (!(tmpInt.equals("T") || (tmpInt.equals("t"))))
						throw new Exception();
					if ((name.length() < 1) || (email.length() < 1)
							|| (indexNumber < 1))
						throw new Exception();
					Student stud = new Student(name, email, indexNumber, null,
							null);
					//System.out.println(factory.getStudentDAO().add(stud));
					System.out.println(((StudentDAO)factory.getDAO(Student.class)).add(stud));
				} catch (Exception e) {
					System.err.println("Przerwano");
				}
			} else {
				// wyszukiwanie po loginie
				try {
					System.out.print("Podaj login lub nazwisko i imie: ");
					name = stdin.readLine();
					System.out
							.println(((StudentDAO)factory.getDAO(Student.class)).getByLogin(name));
				} catch (Exception e) {
					System.err.println("Przerwano");
				}
			}
		}
		/*
		 * System.out.println(factory.getStudentDAO().getByLogin("kowalski@email.com"
		 * ));
		 * System.out.println(factory.getContactsDAO().getUser("Kowalski jan"
		 * ).getId());
		 * System.out.println(factory.getContactsDAO().getUser("kowalski@email.com"
		 * ).getId());
		 */
	}

}
